<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript 打印金字塔</title>
</head>
<style>
    body{
        font-family: cursive;
    }
</style>
<body>

<script>

    var num =5;
    for(var i = 0; i <num; i++){
        var h = num - i -1;
        for(var j = 0; j < h; j++){
            document.write("&nbsp;")
        }
        var nbsp =(i+1)*2-1;

        for(var k = 0;k < nbsp ; k++){
            document.write("*")
        }
        document.write("<br>")
    }

</script>

</body>
</html>